<template>
	<view>

		<view class="inputLayout">
			<!-- 需要匹配的数据 -->
			<textarea v-model="inputStr" 
			placeholder="添加的的数据,以 ' , ' 号隔开"
			 class="inputView"
			  @input="replaceInput()"
			   maxlength="1000"/>
		</view>

		<view>
			<button @click="backResult()">输入添加({{userCount}}人)？确认添加</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				arrAdd: [],
				inputStr: '',
				addValue: '',
				userCount: 0
			}
		},
		methods: {
			backResult() {
				const params = {
					addValue: JSON.stringify(this.arrAdd)
				}; // 准备要传递的参数
				uni.$emit('addData', params); // 触发全局事件，携带参数

				uni.navigateBack({
					delta: 1
				}); // 表示返回的页面数，默认为1 
			},
			replaceInput() {
				console.debug('----------' + this.inputStr + '---------')
				
				const userStrList=this.inputStr.replace(/，/g,",")
				.replace("‘","")
				.replace("’","")
				.replace("\'","")
				.replace("\'","")
				.replace("\\n","")
				.replace(/\d+./g, ",")
				.replace(/\d+,/g, ",")
				this.arrAdd = []
				this.arrAdd = userStrList.split(',')
				this.userCount = this.arrAdd.length
				console.debug('----------' + JSON.stringify(this.arrAdd) + '---------')
			}
		}
	}
</script>

<style>
	.inputView {
		padding: 16rpx;
		background-color: antiquewhite;
		width: 100%;
		font-size: 28rpx;
		
	}

	.inputLayout {
		display: flex;
		margin-top: 32rpx;
		margin-bottom: 32rpx;
		width: 100vw;
	}
</style>